package com.controller.ljl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSONArray;
import com.entity.Order;
import com.entity.Product;
import com.service.ljl.deliverrecordservice;
import com.service.ljl.deliverservice;

@Controller
public class delivercontroller {
	@Autowired
	private deliverservice deliverservice;

	@Autowired
	private deliverrecordservice deliverrecordservice;

	@PostMapping("/deliver_list")
	@ResponseBody
	public Map<Object, Object> findall(@RequestParam("pagesize") int pagesize, @RequestParam("curpage") int currage) {
		return deliverservice.findall(pagesize, currage);
	}

	@PostMapping("/deliver_cus")
	@ResponseBody
	public List<Order> findone(@RequestParam("cusid") Long id) {
		return deliverservice.findone(id);
	}

	@PostMapping("/deliver_cusall")
	@ResponseBody
	public List<Order> findoneall(@RequestParam("cusid") Long id) {
		return deliverservice.findoneall(id);
	}

	@PostMapping("/deliver_add")
	@ResponseBody
	public void add(@RequestBody Map map) {
		deliverservice.add(map);
	}

	@PostMapping("/deliver_delete")
	@ResponseBody
	public void delete(@RequestParam("id") Long id) {
		deliverservice.delete(id);
	}

	@PostMapping("/deliver_deletes")
	@ResponseBody
	public void deletes(@RequestBody JSONArray ids) {
		deliverservice.deletes(JSONArray.parseArray(ids.toString(), Long.class));
	}

	@PostMapping("/deliverrecord_add")
	@ResponseBody
	public void addrecord(@RequestBody Map map) {
		deliverrecordservice.add(map);
	}

	@PostMapping("/deliverrecord_list")
	@ResponseBody
	public Map allrecord(@RequestParam("pagesize") int pagesize, @RequestParam("curpage") int currage) {
		return deliverservice.findrecord(pagesize, currage);
	}

	@PostMapping("/deliverrecord_delete")
	@ResponseBody
	public void deleterecord(@RequestParam("id") Long id) {
		deliverrecordservice.delete(id);
	}

	@PostMapping("/deliverrecord_deletes")
	@ResponseBody
	public void deleterecord(@RequestBody JSONArray ids) {
		deliverrecordservice.deletes(JSONArray.parseArray(ids.toString(), Long.class));
	}

	@PostMapping("/deliverproduct_list")
	@ResponseBody
	public Map product(@RequestParam("id") Long id) {
		return deliverservice.productlist(id);
	}
	
	@PostMapping("/detail_byname")
	@ResponseBody
	public List<Product> findonebyname(@RequestParam("name") String name){
		return deliverservice.findbyname(name);
	}
	
	@PostMapping("/detail_add")
	@ResponseBody
	public void adddetail(@RequestBody Map map) {
		deliverservice.adddeliver(map);
	}

}
